<?php
/**
 * 用户登录的相关
 * Enter description here ...
 * @author Administrator
 *
 */
class Application_Model_Login
{
	/**
	 * 用户的登录信息session命名空间
	 * @var string
	 */
	const LOGIN_SESSION_KEY = "USERINFO";
	
	/**
	 * 验证用户登录
	 * @param string $username
	 * @param string $password
	 * @return boolean
	 */
	public function checkUser($username,$password){
		try{
		    $userM = new Application_Model_DbTable_User();		    
		    $userInfo = $userM->getUserByUsername($username);
		    if(md5($password) == $userInfo->password){
		    	$user_session = new Zend_Session_Namespace(self::LOGIN_SESSION_KEY);
		    	foreach ($userInfo as $key=>$val){
		    		$user_session->$key = $val;
		    	}
		    	return TRUE;
		    }else{
		    	return FALSE;
		    }
		}catch (Exception $e){
			throw $e;
			return FALSE;
		}
	}
	
	/**
	 * 检查是否已经登录
	 * Enter description here ...
	 * @return boolean
	 */
	public function isLoged(){
		$user_session = new Zend_Session_Namespace(self::LOGIN_SESSION_KEY);
		if($user_session->id){
			return TRUE;
		}else{
			return FALSE;
		}
	}
	
	/**
	 * 登出
	 * @retur boolean
	 */
	public function logOut(){
		try{
			Zend_Session::destroy(TRUE);
		}catch(Exception $e){
			return FALSE;
		}
		return TRUE;
	}
}